Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading Parquet string cols when nrows and input_pass_limit > 0 #17321

Conversation

mhaseeb123
Copy link
Member

@mhaseeb123 mhaseeb123 commented Nov 14, 2024

Description

This PR fixes reading string columns in Parquet using chunked parquet reader when nrows and input_pass_limit are > 0.

Closes #17311

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@github-actions github-actions bot added libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API. labels Nov 14, 2024
@mhaseeb123 mhaseeb123 added bug Something isn't working 2 - In Progress Currently a work in progress cuIO cuIO issue non-breaking Non-breaking change breaking Breaking change 3 - Ready for Review Ready for review by team and removed non-breaking Non-breaking change 2 - In Progress Currently a work in progress labels Nov 14, 2024
@pytest.mark.parametrize("pass_read_limit", [0, 240, 1024000000])
@pytest.mark.parametrize("use_pandas_metadata", [True, False])
@pytest.mark.parametrize("num_rows", [1000, 3000, None])
def test_parquet_chunked_reader_structs(
Copy link
Member Author

@mhaseeb123 mhaseeb123 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar test as above (test_parquet_chunked_reader) but with a struct table.

return has_repetition
? ((page_begin <= begin && page_end >= begin) || (page_begin <= end && page_end >= end))
: ((page_begin < begin && page_end > begin) || (page_begin < end && page_end > end));
: ((page_begin < begin && page_end > begin) || (page_begin < end && page_end >= end));
Copy link
Member Author

@mhaseeb123 mhaseeb123 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thrust::for_each(rmm::exec_policy_nosync(_stream),
iter,
iter + pass.pages.size(),
set_final_row_count{pass.pages, pass.chunks});

^Here we adjust the num_rows for the last page when input_pass_limit > 0 to compensate for lists. This leads to a false negative is_bounds_page for the last page of str cols due to the page_end > end predicate. This false negative results in page_bounds() including total size of last page instead of clipping it at nrows. This finally manifests in the out_buf.create_string_data() with larger num_bytes than data size leading to the extra \x00 chars in the column.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nvdbaranec I didn't see the effect of adjusting num_rows for the last page showing up for other col types and is_bounds_page is only used in string decoders so I am hoping other decoders don't rely on a similar predicate (at least doesn't seem like in the tests).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know it's a convoluted bug when the fix is 99% comment.

Should we try to keep the condition and change thenum_rows adjustment? This fix feels like a workaround for incorrect num_rows (expecting to be wrong on this one, but want to make sure we at least consider this).

Copy link
Member Author

@mhaseeb123 mhaseeb123 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikr, I have been debating myself with this one as well. I am not fully sure if we would break things by adjusting num_rows for the last pages of cols (to what?) in generate_list_column_row_count_estimates() and keep the original condition here. Maybe @nvdbaranec or @etseidl can comment here better.

For now, I chose to relax this condition as this function (is_bounds_page()) is only being used in string decoders (narrower scope) and the described problem is only being seen in string cols.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me nervous. So in the normal case, won't this mean every final page is a bounds page, regardless of whether we're using num_rows? That means unnecessary processing when all we want to do is read the entire page anyway. Could we add a boolean argument to is_bounds_page if num_rows has been modified, or add a field to the PageInfo struct? Or maybe do as @vuule suggests (change the num_rows adjustment)...perhaps add an adjusted_num_rows 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, Ed! I have added a new boolean field to PageInfo which tells if the num_rows for this page has been adjusted and if so, we relax the condition.

cpp/src/io/parquet/page_decode.cuh Outdated Show resolved Hide resolved
return has_repetition
? ((page_begin <= begin && page_end >= begin) || (page_begin <= end && page_end >= end))
: ((page_begin < begin && page_end > begin) || (page_begin < end && page_end > end));
: ((page_begin < begin && page_end > begin) || (page_begin < end && page_end >= end));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know it's a convoluted bug when the fix is 99% comment.

Should we try to keep the condition and change thenum_rows adjustment? This fix feels like a workaround for incorrect num_rows (expecting to be wrong on this one, but want to make sure we at least consider this).

@mhaseeb123 mhaseeb123 marked this pull request as ready for review November 14, 2024 20:00
@mhaseeb123 mhaseeb123 requested review from a team as code owners November 14, 2024 20:00
@mhaseeb123 mhaseeb123 requested a review from vuule November 14, 2024 22:41
@mhaseeb123 mhaseeb123 requested a review from etseidl November 15, 2024 17:55
Copy link
Contributor

@etseidl etseidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Thanks for tagging me!

cpp/src/io/parquet/page_decode.cuh Outdated Show resolved Hide resolved
Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving python test changes

@mhaseeb123 mhaseeb123 requested a review from bdice November 15, 2024 19:02
@mhaseeb123 mhaseeb123 added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels Nov 15, 2024
cpp/src/io/parquet/page_decode.cuh Outdated Show resolved Hide resolved
@github-actions github-actions bot added the cudf.polars Issues specific to cudf.polars label Nov 15, 2024
@galipremsagar
Copy link
Contributor

@mhaseeb123 Can we go ahead and merge this pr?

@mhaseeb123
Copy link
Member Author

/merge

@rapids-bot rapids-bot bot merged commit 43f2f68 into rapidsai:branch-24.12 Nov 18, 2024
107 checks passed
@mhaseeb123 mhaseeb123 deleted the bug/pq-chunk-read-str-cols-with-nonzero-nrows-and-input-pass-limit branch November 18, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge breaking Breaking change bug Something isn't working cudf.polars Issues specific to cudf.polars cuIO cuIO issue libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUG] Chunked parquet reader incorrect results for positive values of n_rows
7 participants